Java Applet Interview Questions and Answers
Ques 21. What are the steps involved in Applet development?
Following are the steps involved in Applet development:
► Create/Edit a Java source file. This file must contain a class which extends Applet class.
► Compile your program using javac
► Execute the appletviewer, specifying the name of your applet's source file or html file. In case the applet information is stored in html file then Applet can be invoked using java enabled web browser.
Ques 22. Which method is used to output a string to an applet? Which function is this method included in?
drawString( ) method is used to output a string to an applet. This method is included in the paint method of the Applet.
Ques 23. When is update method called?
Whenever a screen needs redrawing (e.g., upon creation, resizing, validating) the update method is called. By default, the update method clears the screen and then calls the paint method, which normally contains all the drawing code.
Ques 24. How will you communicate between two Applets?
The simplest method is to use the static variables of a shared class since there's only one instance of the class and hence only one copy of its static variables. A slightly more reliable method relies on the fact that all the applets on a given page share the same AppletContext. We obtain this applet context as follows:
AppletContext ac = getAppletContext();
AppletContext provides applets with methods such as getApplet(name), getApplets(),getAudioClip, getImage, showDocument and showStatus().
Ques 25. How do you communicate in between Applets and Servlets?
We can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection and "tunnel" to the web server. The server then passes this information to the servlet in the normal way. Basically, the applet pretends to be a web browser, and the servlet doesn't know the difference. As far as the servlet is concerned, the applet is just another HTTP client.
Most helpful rated by users:
- What is an applet?
- What is the difference between an Applet and an Application?
- How will you establish the connection between the servlet and an applet?
- What is an Applet? Should applets have constructors?
- How will you initialize an Applet?